import request from '@/utils/request'

//同花顺行情
//http://d.10jqka.com.cn/multimarketreal/16,129/1B0016,IH2203_IH2204_IH2206_IH2209/10_65_66_199112
//http://d.10jqka.com.cn/multimarketreal/16,129/1B0300,IF2203_IF2204_IF2206_IF2209/10_65_66_199112
//http://d.10jqka.com.cn/multimarketreal/16,129/1B0905,IC2203_IC2204_IC2206_IC2209/10_65_66_199112
export function get10JqkaQuote(symbol) {
	return request({
		url: '/ajax/get-html',
		method: 'post',
        data: {
            url: 'http://d.10jqka.com.cn/multimarketreal/16,129/'+symbol+'/10_65_66_199112',
            header: [
                {key: 'Content-Type', val: 'application/javascript; charset=GB18030'},
                {key: 'Referer', val: 'http://futures.10jqka.com.cn'},
                {key: 'User-Agent', val: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55'},
                // {key: 'Accept', val: '*/*'},
                // {key: 'Accept-Encoding', val: 'gzip, deflate, br'},
                // {key: 'Content-Encoding', val: 'gzip'},
            ]
        }
	})
}

//http://d.10jqka.com.cn/v6/time/qh_sc9999/last.js
export function get10JqkaQuoteLast(symbol) {
	return request({
		url: '/ajax/get-html',
		method: 'post',
        data: {
            url: 'http://d.10jqka.com.cn/v6/time/qh_'+symbol.toLowerCase()+'9999/last.js',
            header: [
                {key: 'Content-Type', val: 'application/javascript; charset=GB18030'},
                {key: 'Referer', val: 'http://futures.10jqka.com.cn'},
                {key: 'User-Agent', val: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55'},
                // {key: 'Accept', val: '*/*'},
                // {key: 'Accept-Encoding', val: 'gzip, deflate, br'},
                // {key: 'Content-Encoding', val: 'gzip'},
            ]
        }
	})
}

//解析JSON数据
export function prase10JqkaJsStr(html) {
    if (!html) {
        return {}
    }

    let _data = html
    _data = _data.replace(/multimarketreal\(/g, '')
    _data = _data.replace(/quotebridge_v6_time_qh_sc9999_last\(/g, '')
    _data = _data.replace(/\)/g, '')

    let _ret = JSON.parse(_data)

    return _ret
}

export function prase10JqkaJsStrForV6Time(symbol, html) {
    let _ret = 0
    if (!symbol || !html) {
        return _ret
    }
    // debugger
    let _data = prase10JqkaJsStr(html)
    
    let _symbol = 'qh_'+symbol+'9999'
    if (_data[_symbol] && _data[_symbol].data) {
        let _rows = _data[_symbol].data.split(';')
        let _row = _rows[_rows.length - 1].split(',')
        if (_row && _row.length == 5) {
            _ret = _row[1] * 1
        }
    }

    return _ret || 0
}